from game import zz_game
from zz import zz_log, zz_img

log = zz_log.of()


class Game(zz_game.ZZ_Game):
    def __init__(self, d, has_prize=True):
        super().__init__(d, has_prize)

    def get_name(self):
        return "超级逗萌兽"

    def game_alert(self):
        self.alert_close_by_file('./game/img/超级逗萌兽')

    def handle_main(self):
        self.log_msg("等待进入游戏主界面")
        self.img_exit('./game/img/超级逗萌兽/game_main.png', 100)
        self.log_msg("已进入游戏主界面")

        for i in range(3):
            self.game_alert()

            self.log_msg("点击开始闯关")
            self.img_click('./game/img/超级逗萌兽/play.png')

            if self.img_exit('./game/img/超级逗萌兽/play_01.png', 2):
                self.log_msg("点击重新开始")
                self.img_click('./game/img/超级逗萌兽/play_01.png')

            self.log_msg("等待进入战斗界面")
            self.img_exit('./game/img/超级逗萌兽/play_main.png', 100)
            self.log_msg("已进入战斗界面，等等战斗失败")

            while True:
                if self.img_exit('./game/img/超级逗萌兽/play_fail_alert.png', 3):
                    self.log_msg("战斗已失败")
                    break
                self.log_msg("战斗中")

            self.img_click_if_exists('点击下回再战', './game/img/超级逗萌兽/play_fail.png', './game/img/超级逗萌兽/play_fail_01.png')
            self.log_msg("点击确定")
            self.img_click('./game/img/超级逗萌兽/play_fail_01.png')
            self.log_msg("点击直接领取")
            self.img_click('./game/img/超级逗萌兽/play_fail_02.png')

        return True
